﻿using System;
using System.Web.UI;
using StructureMap;
using WholesaleOnline.Contract;
using WholesaleOnline.Controller;
using WholesaleOnline.DataContract.Messaging;

namespace WholesaleOnline.WebUI.Pages
{
    public partial class LoginPage : Page
    {
        public const char BUYER_TYPE = 'B';
        private IAccountService m_service = ObjectFactory.GetInstance<IAccountService>();

        protected void Page_Load(object sender, EventArgs e)
        {
            txtName.Focus();
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            LoginRequest request = new LoginRequest();
            request.AccountName = txtName.Text;
            request.AccountPassword = txtPassword.Text;
            LoginResponse response = m_service.Login(request);
            if (response.Success)
            {
                SessionCache.Current.Merge(SessionCache.LOGIN_ID, response.LoginId);
                if (response.UserType == BUYER_TYPE)
                    Response.Redirect("BuyerHomePage.aspx");
                else
                    lblMessage.Text = "该类型用户还在开发，稍后才会开放!";
            }
            else
            {
                lblMessage.Text = response.Message;
            }
        }
    }
}